using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEditor;
using SgsUI;

namespace SgsUI.Editor
{
    [CustomEditor(typeof(SgsUI.ViewSprite))]
    [CanEditMultipleObjects]
    public class ViewSpriteEditor : ViewEditorBase
    {
        private List<string> m_key_map = new List<string>
        {
            "res","scale9","real_sprite"
        };
        private Dictionary<string,SerializedProperty> m_prop = new Dictionary<string,SerializedProperty>();
        ViewSprite m_sprite;
        protected override void OnEnable()
        {
            base.OnEnable();
            m_sprite = target as ViewSprite;
            foreach(string key in m_key_map)
            {
                m_prop[key] = serializedObject.FindProperty(key);
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            m_sprite.UpdateImage();

            serializedObject.ApplyModifiedProperties();
 
            serializedObject.Update();
            GUI.enabled = false;

            EditorGUILayout.PropertyField(m_prop["res"]);

            if(m_prop["real_sprite"].stringValue != String.Empty)
            {
                EditorGUILayout.PropertyField(m_prop["real_sprite"]);
            }

            if(m_prop["scale9"].boolValue)
            {
                EditorGUILayout.PropertyField(m_prop["scale9"]);
            }
            
            GUI.enabled = true;
        }
    }
}
